home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
basic
/
qbfaqr01.zip
/
MBF2NUM.QRM
< prev
next >
Wrap
Text File
|
1992-07-31
|
2KB
|
73 lines
─ Area: R-QBasic ─────────────────────────────────────────────────────────────
Msg#: 13834 Date: 07-30-92 03:33
From: Nick Dyer Read: Yes Replied: No
To: Robert Laszko Mark:
Subj: Numeric conversion help
──────────────────────────────────────────────────────────────────────────────
RL>
RL>I'm writing a routine to display the number of active records in a
RL>given PCBoard message base file. According to PCBoard's file format
RL>this number is contained in bytes 8 through 11, stored as a Basic S
RL>Precision Real Number. Problem is .... I don't know how to convert
RL>these four bytes into a usable, decimal equivalant.
I think you will find that the following will help if you use Basic
If the 4 byte Basic Real is stored in a string say A$ then,
Q&=CVSMBF(A$)
will place in variable Q& the converted value.
RL>
RL>So what now, coach?? ..... What I'm NOT looking for is the name of
RL>C or Pascal function to do the conversion (but if that's all you ha
RL>I'll take it :) ). I'm using a higher-level language to manipulate
Michael Stewart showed me this technique:
Sub MsFloatToLong (MsFloat As String, L1 As Long)
I1& = Asc(Mid$(MsFloat$, 1))
I2& = Asc(Mid$(MsFloat$, 2))
I3& = Asc(Mid$(MsFloat$, 3))
I4& = Asc(Mid$(MsFloat$, 4))
L1& = ((I1& + (I2& * 256) + (I3& * 65536)) Or &H800000) / (2 ^ (24 -
(I4& - &H80)))
End Sub
Calling the above sub passing the variables containing the four byte basic
real string and a receiving long integer variable will carry out the
conversion necessary.
An unsung hero did this in C, (Author Unknown)
Unsigned long mbf_to_int (m1,m2,m3,exp)
unsigned int m1,m2,m3,exp;
{
return (((m1 + ((unsigned long) m2 << 8) + ((unsigned long) m3 <<
16)) | 0x800000L) >> (24 - (exp - 0x80)));
}
I hope all this helps you. Good Luck!!
Regards
Nick Dyer nick.dyer@almac.co.uk
-!-
■ Orator V1.0 #1■ Mom looted LA & all I got was this lousy tagline.
PCRelay:ALMAC -> #1598 RelayNet (tm)
4.11 ALMAC PC Board BBS +44 (0)324-665371